require(["jquery","template","bootstrap","echarts","bbcare","migrate_jqprint",'jqprint',
    "scprit/department/view/template/follow-up/common.js",
    "oms_config/root"
],function($,template,bootstrap,echarts,$bb,migrate,$print,$common,$root) {
    var URL = $bb.baseUrl("department")+"followup/service";
    var obj=$bb.getPageParams();
    var userId=obj.babyId;
    var type=obj.type;
    var HashMap=$common.hashmap(),hashMap=new HashMap(),checkTime,day;
    history(1,100);
    //打印结果：
    var printBaily = function(){
        var params = $(this).data("params");
        $(params.dom).jqprint({
            debug: false, //如果是true则可以显示iframe查看效果（iframe默认高和宽都很小，可以再源码中调大），默认是false
            importCSS: true, //true表示引进原来的页面的css，默认是true。（如果是true，先会找$("link[media=print]")，若没有会去找$("link")中的css文件）
            printContainer: true, //表示如果原来选择的对象必须被纳入打印（注意：设置为false可能会打破你的CSS规则）。
            operaSupport: true//表示如果插件也必须支持歌opera浏览器，在这种情况下，它提供了建立一个临时的打印选项卡。默认是true
        });
        return ;
    }
    var topbars = [
        {
            "icon":"fa fa-print",
            "name":"打印报告",
            "callback":printBaily,
            "params":{"dom":"#resultInfo"}
        }
    ];
    $bb.toolbar(topbars);

    function getBabyInfo(checkTime,cognitive,understand,express,fineMotor,bigAction) {
        var config = $root.init();
        var showFlag = config.dom.baileyScreeningResultShowInfo ? "1" : "0";
        $bb.ajax({
            url: URL + "/patient/patientInfoPtId",
            data: JSON.stringify({
                data: {
                    "patientId": userId,
                    'showFlag':showFlag
                }
            }),
            success: function (data) {
                if(data.success) {
                    for(var item in data.data){
                        data.data.PatientInfo[item] = data.data[item];
                    }
                    var babyInfo=data.data.PatientInfo;
                    var gender= (babyInfo.gender=="N")? "男":"女";
                    var babyData=$common.babyInfoDeal(babyInfo);
                    $common.infoInitNew({"id":"#babyInfoList","data":babyData});
                    var nowAge =  $common.DateDiff(checkTime, babyInfo.birthday)/30.4;
                    $("#babyInfoList>li").eq(1).html("宝宝月龄："+nowAge.toFixed(1));
                    var date1 = new Date(checkTime);  //开始时间
                    var date2 = new Date(babyInfo.birthday);     //结束时间
                    var date3 = date1.getTime() - date2.getTime();   //时间差的毫秒数
                    //计算出相差天数
                    day=Math.floor(date3/(24*3600*1000));
                    //计算相差的年数
                    var age2 = $common.yearDayWeek(day,babyInfo.pregnancyDay);
                    var years = age2.year;
                    var weeks = age2.week;
                    var days = age2.day;
                    var babyInfo2= '<li class="important"><a>姓名</a><br/><span>'+babyInfo.userName+'</span></li>'+
                        '<li class="important"><a>性别</a><br/><span>'+gender+'</span></li>'+
                        '<li class="important"><a>出生日期</a><br/><span>'+babyInfo.birthday+'</span></li>'+
                        '<li class="important"><a>月龄（岁）</a><br/><span>'+years+'</span></li>'+
                        '<li class="important"><a>月龄（周）</a><br/><span>'+weeks+'</span></li>'+
                        '<li class="important"><a>月龄（天）</a><br/><span>'+days+'</span></li>'+
                        '<li class="important"><a>认知能力</a><br/><span>'+cognitive.toFixed(1)+'</span></li>'+
                        '<li class="important"><a>语言理解</a><br/><span>'+understand.toFixed(1)+'</span></li>'+
                        '<li class="important"><a>语言表达</a><br/><span>'+express.toFixed(1)+'</span></li>'+
                        '<li class="important"><a>精细动作</a><br/><span>'+fineMotor.toFixed(1)+'</span></li>'+
                        '<li class="important"><a>大动作</a><br/><span>'+bigAction.toFixed(1)+'</span></li>';
                    $("#babyInfo").html(babyInfo2);
                    showResult(day,cognitive,understand,express,fineMotor,bigAction);
                }
            }
        });
    }

    function showResult(checkTime,cognitive,understand,express,fineMotor,bigAction) {
        var cognitiveResult = "", understandResult = "", expressResult = "", fineMotorResult = "", bigActionResult = "";
        var DANGEROUS = "存在落后风险", WARN = "边缘", NORMAL = "无明显异常";
        var cognitiveColor, understandColor, expressColor, fineMotorColor, bigActionColor;
        var standard = "", time = "";
        if (16 <= day && day <= 3 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 2) cognitiveResult = WARN;
            if (3 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 == understand)    understandResult = DANGEROUS;
            if (0 < understand && understand <= 2) understandResult = WARN;
            if (3 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 1) expressResult = WARN;
            if (2 <= express && express <= 24) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 2) fineMotorResult = WARN;
            if (3 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 2) bigActionResult = WARN;
            if (3 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;
            time = "<a><span >检查结果：</span><span>16天-3月15天</span></a>";
            standard = '<ul class="clearfix" style="height: 30px;"><li><a>认知能力</a></li><li><a>/</a></li><li><a>0-2</a></li><li><a>3-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>/</a></li><li><a>1-2</a></li><li><a>3-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>/</a></li><li><a>0-1</a></li><li><a>2-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>/</a></li><li><a>0-2</a></li><li><a>3-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>/</a></li><li><a>0-2</a></li><li><a>3-28</a></li></ul>';

        } else if (3 * 30 + 16 <= day && day <= 6 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 3) cognitiveResult = DANGEROUS;
            if (4 <= cognitive && cognitive <= 6) cognitiveResult = WARN;
            if (7 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 <= understand && understand <= 3)    understandResult = DANGEROUS;
            if (4 <= understand && understand <= 5) understandResult = WARN;
            if (6 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 2) expressResult = DANGEROUS;
            if (3 <= express && express <= 4) expressResult = WARN;
            if (5 <= express && express <= 24) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 3) fineMotorResult = DANGEROUS;
            if (4 <= fineMotor && fineMotor <= 6) fineMotorResult = WARN;
            if (7 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 4) bigActionResult = DANGEROUS;
            if (5 <= bigAction && bigAction <= 6) bigActionResult = WARN;
            if (7 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

            time = "<a><span >检查结果：</span><span> 3月16天-6月15天</span></a>";
            standard = '<ul class="clearfix"><li><a>认知能力</a></li><li><a>0-3</a></li><li><a>4-6</a></li><li><a>7-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>0-3</a></li><li><a>4-5</a></li><li><a>6-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>0-2</a></li><li><a>3-4</a></li><li><a>5-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>0-3</a></li><li><a>4-6</a></li><li><a>7-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>0-4</a></li><li><a>5-6</a></li><li><a>7-28</a></li></ul>';
        } else if (6 * 30 + 16 <= day && day <= 9 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 6) cognitiveResult = DANGEROUS;
            if (7 <= cognitive && cognitive <= 9) cognitiveResult = WARN;
            if (10 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 <= understand && understand <= 5)    understandResult = DANGEROUS;
            if (6 <= understand && understand <= 7) understandResult = WARN;
            if (8 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 3) expressResult = DANGEROUS;
            if (4 <= express && express <= 5) expressResult = WARN;
            if (6 <= express && express <= 24) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 6) fineMotorResult = DANGEROUS;
            if (7 <= fineMotor && fineMotor <= 8) fineMotorResult = WARN;
            if (9 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 7) bigActionResult = DANGEROUS;
            if (8 <= bigAction && bigAction <= 10) bigActionResult = WARN;
            if (11 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

            time = "<a><span >检查结果：</span><span> 6月16天-9月15天</span></a>";
            standard = '<ul class="clearfix"><li><a>认知能力</a></li><li><a>0-6</a></li><li><a>7-9</a></li><li><a>10-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>0-5</a></li><li><a>6-7</a></li><li><a>8-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>0-3</a></li><li><a>4-5</a></li><li><a>6-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>0-6</a></li><li><a>7-8</a></li><li><a>9-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>0-7</a></li><li><a>8-10</a></li><li><a>11-28</a></li></ul>';
        } else if (9 * 30 + 16 <= day && day <= 12 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 9) cognitiveResult = DANGEROUS;
            if (10 <= cognitive && cognitive <= 13) cognitiveResult = WARN;
            if (14 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 <= understand && understand <= 6)    understandResult = DANGEROUS;
            if (7 <= understand && understand <= 9) understandResult = WARN;
            if (10 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 4) expressResult = DANGEROUS;
            if (5 <= express && express <= 8) expressResult = WARN;
            if (9 <= express && express <= 24) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 8) fineMotorResult = DANGEROUS;
            if (9 <= fineMotor && fineMotor <= 10) fineMotorResult = WARN;
            if (11 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 10) bigActionResult = DANGEROUS;
            if (11 <= bigAction && bigAction <= 12) bigActionResult = WARN;
            if (13 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

            time = "<a><span >检查结果：</span><span> 9月16天-12月15天</span></a>";
            standard = '<ul class="clearfix"><li><a>认知能力</a></li><li><a>0-9</a></li><li><a>10-13</a></li><li><a>14-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>0-6</a></li><li><a>7-9</a></li><li><a>10-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>0-4</a></li><li><a>5-8</a></li><li><a>9-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>0-8</a></li><li><a>9-10</a></li><li><a>11-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>0-10</a></li><li><a>11-12</a></li><li><a>13-28</a></li></ul>';
        } else if (12 * 30 + 16 <= day && day <= 18 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 13) cognitiveResult = DANGEROUS;
            if (14 <= cognitive && cognitive <= 16) cognitiveResult = WARN;
            if (17 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 <= understand && understand <= 9)    understandResult = DANGEROUS;
            if (10 <= understand && understand <= 11) understandResult = WARN;
            if (12 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 9) expressResult = DANGEROUS;
            if (10 <= express && express <= 12) expressResult = WARN;
            if (13 <= express && express <= 24) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 10) fineMotorResult = DANGEROUS;
            if (11 <= fineMotor && fineMotor <= 13) fineMotorResult = WARN;
            if (14 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 12) bigActionResult = DANGEROUS;
            if (13 <= bigAction && bigAction <= 16) bigActionResult = WARN;
            if (17 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

            time = "<a><span >检查结果：</span><span>12月16天-18月15天</span></a>";
            standard = '<ul class="clearfix"><li><a>认知能力</a></li><li><a>0-13</a></li><li><a>14-16</a></li><li><a>17-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>0-9</a></li><li><a>10-11</a></li><li><a>12-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>0-10</a></li><li><a>10-12</a></li><li><a>13-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>0-10</a></li><li><a>11-13</a></li><li><a>14-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>0-12</a></li><li><a>13-16</a></li><li><a>17-28</a></li></ul>';
        } else if (18 * 30 + 16 <= day && day <= 24 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 16) cognitiveResult = DANGEROUS;
            if (17 <= cognitive && cognitive <= 20) cognitiveResult = WARN;
            if (21 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 <= understand && understand <= 11)    understandResult = DANGEROUS;
            if (12 <= understand && understand <= 15) understandResult = WARN;
            if (16 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 11) expressResult = DANGEROUS;
            if (12 <= express && express <= 15) expressResult = WARN;
            if (16 <= express && express <= 24) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 11) fineMotorResult = DANGEROUS;
            if (12 <= fineMotor && fineMotor <= 16) fineMotorResult = WARN;
            if (17 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 16) bigActionResult = DANGEROUS;
            if (17 <= bigAction && bigAction <= 18) bigActionResult = WARN;
            if (19 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

            time = "<a><span >检查结果：</span><span>18月16天-24月15天</span></a>";
            standard = '<ul class="clearfix"><li><a>认知能力</a></li><li><a>0-16</a></li><li><a>17-20</a></li><li><a>21-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>0-11</a></li><li><a>12-15</a></li><li><a>16-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>0-10</a></li><li><a>12-15</a></li><li><a>16-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>0-11</a></li><li><a>12-16</a></li><li><a>17-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>0-16</a></li><li><a>17-18</a></li><li><a>19-28</a></li></ul>';
        } else if (24 * 30 + 16 <= day && day <= 30 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 20) cognitiveResult = DANGEROUS;
            if (21 <= cognitive && cognitive <= 24) cognitiveResult = WARN;
            if (25 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 <= understand && understand <= 12)    understandResult = DANGEROUS;
            if (13 <= understand && understand <= 18) understandResult = WARN;
            if (19 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 12) expressResult = DANGEROUS;
            if (13 <= express && express <= 18) expressResult = WARN;
            if (19 <= express && express <= 24) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 14) fineMotorResult = DANGEROUS;
            if (15 <= fineMotor && fineMotor <= 18) fineMotorResult = WARN;
            if (19 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 18) bigActionResult = DANGEROUS;
            if (19 <= bigAction && bigAction <= 21) bigActionResult = WARN;
            if (22 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

            time = "<a><span >检查结果：</span><span>24月16天-30月15天</span></a>";
            standard = '<ul class="clearfix"><li><a>认知能力</a></li><li><a>0-20</a></li><li><a>21-24</a></li><li><a>25-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>0-12</a></li><li><a>13-18</a></li><li><a>19-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>0-12</a></li><li><a>13-18</a></li><li><a>16-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>0-14</a></li><li><a>15-18</a></li><li><a>19-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>0-18</a></li><li><a>19-21</a></li><li><a>22-28</a></li></ul>';
        } else if (30 * 30 + 16 <= day && day <= 36 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 22) cognitiveResult = DANGEROUS;
            if (23 <= cognitive && cognitive <= 27) cognitiveResult = WARN;
            if (28 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 <= understand && understand <= 12)    understandResult = DANGEROUS;
            if (13 <= understand && understand <= 20) understandResult = WARN;
            if (21 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 14) expressResult = DANGEROUS;
            if (15 <= express && express <= 20) expressResult = WARN;
            if (21 <= express && express <= 24) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 17) fineMotorResult = DANGEROUS;
            if (18 <= fineMotor && fineMotor <= 22) fineMotorResult = WARN;
            if (23 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 18) bigActionResult = DANGEROUS;
            if (19 <= bigAction && bigAction <= 23) bigActionResult = WARN;
            if (24 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

            time = "<a><span >检查结果：</span><span>30月16天-36月15天</span></a>";
            standard = '<ul class="clearfix"><li><a>认知能力</a></li><li><a>0-22</a></li><li><a>23-27</a></li><li><a>28-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>0-12</a></li><li><a>13-20</a></li><li><a>21-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>0-14</a></li><li><a>15-20</a></li><li><a>21-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>0-17</a></li><li><a>18-22</a></li><li><a>23-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>0-18</a></li><li><a>19-23</a></li><li><a>24-28</a></li></ul>';
        } else if (36 * 30 + 16 <= day && day <= 42 * 30 + 15) {
            if (0 <= cognitive && cognitive <= 24) cognitiveResult = DANGEROUS;
            if (25 <= cognitive && cognitive <= 31) cognitiveResult = WARN;
            if (32 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

            if (0 <= understand && understand <= 14)    understandResult = DANGEROUS;
            if (15 <= understand && understand <= 22) understandResult = WARN;
            if (23 <= understand && understand <= 24) understandResult = NORMAL;

            if (0 <= express && express <= 15) expressResult = DANGEROUS;
            if (16 <= express && express <= 23) expressResult = WARN;
            if (24 == express) expressResult = NORMAL;

            if (0 <= fineMotor && fineMotor <= 17) fineMotorResult = DANGEROUS;
            if (18 <= fineMotor && fineMotor <= 25) fineMotorResult = WARN;
            if (26 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

            if (0 <= bigAction && bigAction <= 20) bigActionResult = DANGEROUS;
            if (21 <= bigAction && bigAction <= 26) bigActionResult = WARN;
            if (27 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

            time = "<a><span >检查结果：</span><span>36月16天-42月15天</span></a>";
            standard = '<ul class="clearfix"><li><a>认知能力</a></li><li><a>0-24</a></li><li><a>25-31</a></li><li><a>32-33</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言理解</a></li><li><a>0-14</a></li><li><a>15-22</a></li><li><a>23-24</a></li></ul>' +
                '<ul class="clearfix"><li><a>语言表达</a></li><li><a>0-15</a></li><li><a>16-23</a></li><li><a>24</a></li></ul>' +
                '<ul class="clearfix"><li><a>精细动作</a></li><li><a>0-15</a></li><li><a>16-25</a></li><li><a>26-27</a></li></ul>' +
                '<ul class="clearfix"><li><a>大动作</a></li><li><a>0-20</a></li><li><a>21-26</a></li><li><a>27-28</a></li></ul>';
        }

       /* $("#time").html(time);*/
        $(".mainCenterBottomRes").html(standard);
        var oLis= $(".outcomes>ul>li");
        if (cognitiveResult == DANGEROUS) {
            oLis.eq(0).find("div[class^='border']").addClass("lose3").removeClass("lose1 lose2").find(".ss").addClass("lose-3").removeClass("lose-1 lose-2");
            cognitiveColor = "#ff7043";
            $("#cognitiveResult").html('√');
        }
        if (cognitiveResult == WARN) {
            oLis.eq(0).find("div[class^='border']").addClass("lose2").removeClass("lose1 lose3").find(".ss").addClass("lose-2").removeClass("lose-1 lose-3");
            cognitiveColor = "#ffa726";
            $("#cognitiveResult").html('√');
        }
        if (cognitiveResult == NORMAL) {
            oLis.eq(0).find("div[class^='border']").addClass("lose1").removeClass("lose2 lose3").find(".ss").addClass("lose-1").removeClass("lose-2 lose-3");
            cognitiveColor = "#9ccc65";
        }
        if (understandResult == DANGEROUS) {
            oLis.eq(1).find("div[class^='border']").addClass("lose3").removeClass("lose1 lose2").find(".ss").addClass("lose-3").removeClass("lose-1 lose-2");
            understandColor = "#ff7043";
            $("#understandResult").html('√');
        }
        if (understandResult == WARN) {
            oLis.eq(1).find("div[class^='border']").addClass("lose2").removeClass("lose1 lose3").find(".ss").addClass("lose-2").removeClass("lose-1 lose-3");
            understandColor = "#ffa726";
            $("#understandResult").html('√');
        }
        if (understandResult == NORMAL) {
            oLis.eq(1).find("div[class^='border']").addClass("lose1").removeClass("lose2 lose3").find(".ss").addClass("lose-1").removeClass("lose-2 lose-3");
            understandColor = "#9ccc65";
        }
        if (expressResult == DANGEROUS) {
            oLis.eq(2).find("div[class^='border']").addClass("lose3").removeClass("lose1 lose2").find(".ss").addClass("lose-3").removeClass("lose-1 lose-2");
            expressColor = "#ff7043";
            $("#expressResult").html('√');
        }
        if (expressResult == WARN) {
            oLis.eq(2).find("div[class^='border']").addClass("lose2").removeClass("lose1 lose3").find(".ss").addClass("lose-2").removeClass("lose-1 lose-3");
            expressColor = "#ffa726";
            $("#expressResult").html('√');
        }
        if (expressResult == NORMAL) {
            oLis.eq(2).find("div[class^='border']").addClass("lose1").removeClass("lose2 lose3").find(".ss").addClass("lose-1").removeClass("lose-2 lose-3");
            expressColor = "#9ccc65";
        }
        if (fineMotorResult == DANGEROUS) {
            oLis.eq(3).find("div[class^='border']").addClass("lose3").removeClass("lose1 lose2").find(".ss").addClass("lose-3").removeClass("lose-1 lose-2");
            fineMotorColor = "#ff7043";
            $("#fineMotorResult").html('√');
        }
        if (fineMotorResult == WARN) {
            oLis.eq(3).find("div[class^='border']").addClass("lose2").removeClass("lose1 lose3").find(".ss").addClass("lose-2").removeClass("lose-1 lose-3");
            fineMotorColor = "#ffa726";
            $("#fineMotorResult").html('√');
        }
        if (fineMotorResult == NORMAL) {
            oLis.eq(3).find("div[class^='border']").addClass("lose1").removeClass("lose2 lose3").find(".ss").addClass("lose-1").removeClass("lose-2 lose-3");
            fineMotorColor = "#9ccc65";
        }
        if (bigActionResult == DANGEROUS) {
            oLis.eq(4).find("div[class^='border']").addClass("lose3").removeClass("lose1 lose2").find(".ss").addClass("lose-3").removeClass("lose-1 lose-2");
            bigActionColor = "#ff7043";
            $("#bigActionResult").html('√');
        }
        if (bigActionResult == WARN) {
            oLis.eq(4).find("div[class^='border']").addClass("lose2").removeClass("lose1 lose3").find(".ss").addClass("lose-2").removeClass("lose-1 lose-3");
            bigActionColor = "#ffa726";
            $("#bigActionResult").html('√');
        }
        if (bigActionResult == NORMAL) {
            oLis.eq(4).find("div[class^='border']").addClass("lose1").removeClass("lose2 lose3").find(".ss").addClass("lose-1").removeClass("lose-2 lose-3");
            bigActionColor = "#9ccc65";
        }
        oLis.eq(0).find(".score").html(cognitive+"分").siblings().find(".res-score").html(cognitiveResult);
        oLis.eq(1).find(".score").html(understand+"分").siblings().find(".res-score").html(understandResult);
        oLis.eq(2).find(".score").html(express+"分").siblings().find(".res-score").html(expressResult);
        oLis.eq(3).find(".score").html(fineMotor +"分").siblings().find(".res-score").html(fineMotorResult);
        oLis.eq(4).find(".score").html(bigAction+"分").siblings().find(".res-score").html(bigActionResult);

        $("#showResult").html('<div class="echarts"><div id="myChart" style="height: 300px; width:100%;"></div></div>');
        var myChart = echarts.init(document.getElementById('myChart'));
        var option = {
            tooltip: {trigger: 'axis'},
            calculable: true,
            grid: {
                top:'8%',
                left: '3%',
                right: '4%',
                bottom: '0',
                containLabel: true
            },
            xAxis: [{
                axisLabel: {
                    textStyle: {
                        fontSize: 15
                    }
                },
                type: 'category',
                data: ['认知能力', '语言理解', '语言表达', '精细动作', '大动作']
            }],
            yAxis: {
                axisLabel: {
                    textStyle: {
                        fontSize: 15
                    }
                }, type: 'value', min: 0
            },
            series: [{
                name: '评分',
                type: 'bar',
                barWidth:50,
                itemStyle: {
                    normal: {
                        color: function (params) {
                            var colorList = [
                                cognitiveColor, understandColor, expressColor, fineMotorColor, bigActionColor
                            ];
                            return colorList[params.dataIndex]
                        },
                        label: {
                            show: true,
                            position: 'top',
                            formatter: '{c}.0',
                            textStyle: {
                                fontSize: 22
                            }
                        }
                    }
                },
                data: [cognitive, understand, express, fineMotor, bigAction]
            }]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        $("#infoChart").html('<img src="' + myChart.getDataURL() + '" style="width: 100%;height:100%; "/>').css('display', 'block');
    }

    function getGuide() {
        $bb.ajax({
            url: URL + "/patient/evaluation/getGuide",
            data: JSON.stringify({
                data: {
                    "examinationPaperName": type,
                    "userId": userId
                }
            }),
            success: function (data) {
                if(data.success) {
                    $("#guide").html(data.data.guide);
                    $("#guide1").html("<a id='yj'>指导意见：</a>"+data.data.guide);
                }
            }
        });
    }

    $("#historyList").on('click',"li[result]",function () {
        var result = eval("("+hashMap.get($(this).attr("result")).replace(/\=/g,"\:")+")");
        $(this).addClass("checked").siblings().removeClass("checked");
        $("#checkTime").html($(this).attr("testTime"));
        $("#checkName").html($(this).attr("doctorName"));
        checkTime = $(this).attr("testTime");
        var day= 0,cognitive=result.cognitive*1.0, understand=result.understand*1.0, express=result.express*1.0, fineMotor=result.fineMotor*1.0, bigAction=result.bigAction*1.0;
        getBabyInfo(checkTime,cognitive,understand,express,fineMotor,bigAction);
        getGuide();
    });
    function history(page,rows){
        $bb.ajax({
            url: URL + "/patient/evaluation/getHistoryScore",//baby地址
            async: false,
            data: JSON.stringify({
                data: {
                    "userId": userId,
                    "examinationPaperName": type,
                    "page": page,
                    "rows": rows
                }
            }),
            success: function (data) {
                if (data.success) {
                    hashMap = new HashMap();
                   var  count = data.total;
                    if (count == 0) {
                        $bb.toastShow("患者还未参与该项测评！");
                    }else{
                        var str = '';
                        for (var i = 0; i < data.rows.length; i++) {
                            var testTime = data.rows[i].createTime.substring(0,10);
                            hashMap.put(data.rows[i].answerId, data.rows[i].result);
                            str += '<li  result="' + data.rows[i].answerId + '" doctorName="'+data.rows[i].doctorName+'" testTime="'+testTime+'">'+ data.rows[i].createTime + '</li>';
                        }
                        $("#historyList").html(str);
                        var list1,checkTime;
                        if(obj.answerId){
                            $("#historyList").find("li").each(function(i){
                                var $this=$(this);
                                if($this.attr("result")==obj.answerId){
                                    $this.addClass("checked");
                                    list1=hashMap.get(obj.answerId).replace(/\=/g,"\:");
                                    $("#checkTime").html($(this).attr("testTime"));
                                    $("#checkName").html($(this).attr("doctorName"));
                                    checkTime = $(this).attr("testTime");
                                }
                            });
                        }else{
                            $("#historyList li").eq(0).addClass("checked");
                            list1=hashMap.get($("#historyList li").eq(0).attr("result")).replace(/\=/g,"\:");
                            $("#checkTime").html($("#historyList li").eq(0).attr("testTime"));
                            $("#checkName").html($("#historyList li").eq(0).attr("doctorName"));
                            checkTime = $("#historyList li").eq(0).attr("testTime");
                        }
                        var result=eval("("+list1+")");
                        var day= 0,cognitive=result.cognitive*1.0, understand=result.understand*1.0, express=result.express*1.0, fineMotor=result.fineMotor*1.0, bigAction=result.bigAction*1.0;
                        getBabyInfo(checkTime,cognitive,understand,express,fineMotor,bigAction);
                        getGuide();
                    }
                }
            }
        });
    }

    $(window).resize(function(){
        var width= $("#myChart").width();
        $("#myChart>div").css({"width":width});
        $("#myChart>div>canvas").css({"width":width});
    });
});